import "./index.css"

var data = [{
    id: 0,
    name: '刘泓吉',
    group: 'Web'
}, {
    id: 1,
    name: '宋冰烊',
    group: 'Web'
}, {
    id: 2,
    name: '付子豪',
    group: 'iOS'
}, {
    id: 3,
    name: '李沈阳',
    group: '安卓'
}, {
    id: 4,
    name: '任基伟',
    group: '后台'
}, {
    id: 5,
    name: '李云',
    group: '后台'
}, {
    id: 6,
    name: '王旭',
    group: 'iOS'
}, {
    id: 7,
    name: '房彤',
    group: 'iOS'
}, {
    id: 8,
    name: '杨旭',
    group: '安卓'
}, {
    id: 9,
    name: '李碧琪',
    group: '后台'
}, {
    id: 10,
    name: '朱春涛',
    group: '后台'
}, {
    id: 11,
    name: '潘重阳',
    group: 'Web'
}]

var tbody = document.querySelector('tbody');

var nameSearch = document.querySelector('.name-search');
var name = document.querySelector('.name');

var group = document.querySelector('.group');

setData(data);

function setData(myData) {
    tbody.innerHTML = '';
    myData.forEach(function(value) {
        var tr = document.createElement('tr');
        tbody.appendChild(tr);
        tr.innerHTML = '<td>' + value.name + '</td> <td>' + value.group + '</td> <td><a onclick=window.parent.$router.push(' + '"pc/evaluate-applicant"' + ');>开始面试</a></td>';
    })
}

// priceSearch.addEventListener('click', function() {
//     var newData = data.filter(function(value) {
//         return value.price <= end.value && value.price >= start.value;
//     })

//     setData(newData);
// })

nameSearch.addEventListener('click', function() {
    if (name.value == '') {
        setData(data);
        return;
    }

    var arr = [];

    data.some(function(value) {
        if (value.name.includes(name.value)) {
            arr.push(value);
        }
    })

    setData(arr);
})

name.addEventListener("keydown", function(e) {
    // 按下回车键且输入框值非空时
    if (e.keyCode == 13) {
        nameSearch.click();
    }
})

group.addEventListener('blur', function() {
    if (group.value == 'all') {
        setData(data);
        return;
    }
    var arr = [];
    data.some(function(value) {
        if (value.group === group.value) {
            arr.push(value);
            // return true;
        }
    })

    setData(arr);
})

// var aLis = tbody.querySelectorAll('a');

// for (var i = 0; i < aLis.length; i++) {
//     aLis[i].addEventListener('click', function() {
//         window.parent.$router.push("pc/begin-interview");
//     })
// }